<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //假如有10个
      /*
            0+10/3 = 3  10/3+10%3=4
            3+4/3=4    4/3 + 4%3=2
            因为3-2 ===1 所以总汽水数量为4+1=5
            */

      /*100个空瓶子
            汽水数量       空瓶子数量
            0+100/3 = 33  100%3+100/3=34
            33+34/3 = 44  34%3+ 34/3= 12
            44+12/3 = 48  12%3 + 12/3 = 4
            48+4/3=49     4%3+4/3=2
            因为 3-2 === 1 所以 总汽水数量为49+1 = 50*/

      // 33  33
      // 33 + 11 11
      // 44 + 3=47 2 + 3=5
      // 47 + 1=48 1 + 1=2
      // 49
      function getWaters(bottle, pm) {
        // 设汽水初始值为0
        let sumWaters = 0
        // while循环
        while (bottle >= pm) {
          // 汽水
          sumWaters = sumWaters + Math.floor(bottle / pm)
          // 空瓶子=
          bottle = Math.floor(bottle / pm) + Math.floor(bottle % pm)
        }
        if (bottle - pm === 1) {
          sumWaters++
        }
        return sumWaters
      }
      console.log(getWaters(100, 3))
      console.log(getWaters(90, 3))
      console.log(getWaters(80, 3))
    </script>
  </body>
</html>
